using Tycho.Parser.Tokens;

namespace Tycho.Parser.Peg {
    public class Grammar<Context> {
        private readonly Production<Context> Production;

        public Grammar (Production<Context> production) {
            Production = production;
        }

        public Term Parse (Token[] tokens, Context context) {
            ParseResult<Context> result = Production.Parse (tokens, 0, context);
            if (result != null && result.Index == tokens.Length) {
                return result.Term;
            } else {
                return null;
            }
        }
    }
}